package com.service.lyxmservice.service.article;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.service.lyxmservice.dao.ArticleDetailDao;
import com.service.lyxmserviceapi.model.ArticleModel;
import com.service.lyxmserviceapi.service.ArticleDetailService;
@Service
public class ArticleDetailServiceImpl implements ArticleDetailService{
	@Autowired
	private ArticleDetailDao articleDetailDao;
	@Override
	public ArticleModel getOneArticleModel(String articleId) {
		System.out.println("service-----------------------------------");
		ArticleModel articleModel = articleDetailDao.getArticleById(articleId);
		//分割target标签
		if(articleModel.getTarget()==null&&articleModel.getTarget()==""){
			String []target = articleModel.getTarget().split(",");
			List<String> targetList = new ArrayList<String>();
			for(int x= 0;x<target.length;x++){
				targetList.add(target[x]);
			}
			articleModel.setTargetList(targetList);
		}
		
		return articleModel;
	}
	@Override
	public List<ArticleModel> getArticleModelListWithOutOneId(String articleId,
			String authorId) {
		List<ArticleModel> articleListModel = articleDetailDao.getArticleModelListWithOutOneId(articleId,authorId);
		if(articleListModel!=null){
			if(articleListModel.size()>3){
				articleListModel = articleListModel.subList(0,3);
			}
		}
		System.out.println(articleListModel.size()+"====================");
		return articleListModel;
	}
	/**
	 * 获取首页最新的三篇文章
	 */
	@Override
	public List<ArticleModel> getArticleModelListIndex() {
		// TODO Auto-generated method stub
		List<ArticleModel> articleListModel = articleDetailDao.getArticleModelListIndex();
		if(articleListModel!=null){
			if(articleListModel.size()>3){
				articleListModel = articleListModel.subList(0,3);
			}
		}
		System.out.println(articleListModel.size()+"====================");
		return articleListModel;
	}
	
	

}
